import React, { Component } from 'react'
import PropTypes from 'prop-types'
export default class index extends Component {
    // 对接受的props进行类型和必要性限制
    static propTypes = {
        handleSearch: PropTypes.func.isRequired
    }
    handleGetValue=(e)=>{
        console.log('搜索', e.target.value)
    }
    handleEnter=(e)=>{
        if(e.keyCode!==13){
            return
        }
        console.log('回车', e.target.value)
        if(!e.target.value.trim()){
            return alert('请输入搜索内容')
        }
        this.props.handleSearch(e.target.value)
    }
  render() {
    return (
        <div className="todo-header">
            <input type="text" placeholder="请输入你的任务名称，按回车键确认" onChange={this.handleGetValue} onKeyUp={this.handleEnter}/>
        </div>
    )
  }
}
